import { _decorator, instantiate, Node } from 'cc';
import YangLeGeYang_GameManager from "../../SubGame/YangLeGeYang/Script/Manager/YangLeGeYang_GameManager";

export default class ShuaiFunction {
    //    //销毁子物体
    public static DestroyAllChildren(parent: Node) {
        for (var i = 0; i <= parent.children.length - 1; i++) {
            var child: Node = parent.children[i];
            child.destroy();
        }
    }
    //    //设置所有子物体可见或者不可见
    public static SetAllChildrenAtive(parent: Node, active: boolean) {
        for (var i = 0; i <= parent.children.length - 1; i++) {
            var child: Node = parent.children[i];
            child.active = active;
        }
    }
    public static GetFreeChild(parent: Node): Node {
        var c: Node = null;
        for (var i = 0; i <= parent.children.length - 1; i++) {
            var child = parent.children[i];
            if (child.active == false) {
                c = child;
                break;
            }
        }

        if (c == null) {
            var node: Node = instantiate(parent.children[0]);
            node.parent = parent;
            node.setPosition(0, 0);
            c = node;
        }

        return c;
    }
    //    //延时函数
    public static DelayFunction(_callback: Function, _complete: Function, _loop: number = 1, _duration: number = 1) {
        if (_callback) {
            _callback();
        }

        if (_loop <= 1) {
            if (_complete) {
                _complete();
            }
            return;
        }

        let count = 1;
        let callback = function () {
            if (_callback) {
                _callback();
            }

            if (count >= _loop - 1) {
                YangLeGeYang_GameManager.Instance.unschedule(callback);

                if (_complete) {
                    _complete();
                }
            }

            count++;
        }
        YangLeGeYang_GameManager.Instance.schedule(callback, _duration);
    }
    //    // 设置体力
    public static SetFTG(setNumber: number) {
        //        // DataManager.Instance.configVo.FTGNumber = setNumber;
        //        // DataManager.Instance.writeConfigVo();
        //        // cc.systemEvent.emit('changeFTG');
    }
    //    // 改变体力
    public static ChangeFTG(changeNumber: number) {
        // if (changeNumber == 0) {
        // return;
        // }

        //        // DataManager.Instance.configVo.FTGNumber += changeNumber;
        //        // DataManager.Instance.writeConfigVo();
        //        // cc.systemEvent.emit('changeFTG');
    }
    //    // 将时间转换为"00:00"格式
    public static FormatTime(time) {
        // var minute: any = (Math.floor(time / 60) % 60)
        // var second: any = (time % 60)

        // if (minute.toString().length <= 1) {
        // minute = "0" + minute.toString();
        // }
        // if (second.toString().length <= 1) {
        // second = "0" + second.toString();
        // }

        // return minute + ":" + second;
    }
    //    // [min-max]的随机整数
    public static GetRandomNumber(min, max) {
        // parseInt(Math.random() * (max - min + 1) + min, 10);
        // return Math.floor(Math.random() * (max - min + 1) + min);
    }
    //    // 获取当前日期的凌晨
    public static GetDate0(currentDate: Date, addDay: number = 0) {
        // let nextDate0: Date;

        // let currentDate_copy = new Date(currentDate);
        // currentDate_copy.setHours(0);
        // currentDate_copy.setMinutes(0);
        // currentDate_copy.setSeconds(0);
        // currentDate_copy.setMilliseconds(0);

        // nextDate0 = new Date(currentDate_copy.getTime() + addDay * (60 * 60 * 24 * 1000));
        // return nextDate0;
    }
    //    // 是否是今天首次分享
    public static GetIsFirstShareVideoToday() {
        //        // let isFirstShareVideoToday = false;

        //        // let nowDate = new Date();
        //        // let lastDate = new Date(DataManager.Instance.configVo.lastShareVideoTime);
        //        // let nowDate_0 = ShuaiFunction.GetDate0(nowDate);
        //        // let lastDate_0 = ShuaiFunction.GetDate0(lastDate);
        //        // if (nowDate_0 > lastDate_0) {
        //        //     // DataManager.Instance.configVo.lastShareVideoTime = nowDate.getTime();
        //        //     // DataManager.Instance.writeConfigVo();

        //        //     isFirstShareVideoToday = true;
        //        // }
        //        // else {
        //        //     isFirstShareVideoToday = false;
        //        // }

        //        // return isFirstShareVideoToday;
    }
    //    // 不是Null或者Undefined
    public static IsNotNil(_param) {
        // if (_param === null || _param === undefined) {
        // return false;
        // }
        // else {
        // return true;
        // }
    }
    static checkIntersectOrContain(nodeA: Node, nodeB: Node) {
        // const boundingBoxA = nodeA.getBoundingBoxToWorld();
        // const boundingBoxB = nodeB.getBoundingBoxToWorld();
        // const intersect = boundingBoxA.intersects(boundingBoxB);
        // const AcontainB = boundingBoxA.containsRect(boundingBoxB);
        // const BcontainA = boundingBoxB.containsRect(boundingBoxA);
        // return intersect || AcontainB || BcontainA;
    }
}